package com.sinbader.xiaole.admin.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import com.sinbader.xiaole.common.model.params.WarehouseMoveDetailParam;
import com.sinbader.xiaole.common.model.xiaolevo.WarehouseMoveDetailVo;
import com.sinbader.xiaole.common.entity.WarehouseMove;
import com.sinbader.xiaole.common.enums.NumberUtilEnum;
import com.sinbader.xiaole.common.model.params.WarehouseMoveParam;
import com.sinbader.xiaole.common.service.WarehouseMoveDetailService;
import com.sinbader.xiaole.common.service.WarehouseMoveService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.sinbader.xiaole.common.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;


/**
 * 仓库移货管理控制器
 */
@Api("仓库移货管理")
@Controller
@RequestMapping("/warehouseMove")
public class WarehouseMoveController extends BaseController {

    private String PREFIX = "/warehouseMove";

    @Autowired
    private WarehouseMoveService warehouseMoveService;

    @Autowired
    private WarehouseMoveDetailService warehouseMoveDetailService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/warehouseMove.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/warehouseMove_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/warehouseMove_edit.html";
    }

    @ApiOperation(value = "新增")
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(WarehouseMoveParam warehouseMoveParam) {
        this.warehouseMoveService.add(warehouseMoveParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "编辑")
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(WarehouseMoveParam warehouseMoveParam) {
        this.warehouseMoveService.update(warehouseMoveParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "删除")
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(WarehouseMoveParam warehouseMoveParam) {
        this.warehouseMoveService.delete(warehouseMoveParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "查看详情")
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(WarehouseMoveParam warehouseMoveParam) {
        WarehouseMove detail = this.warehouseMoveService.getById(warehouseMoveParam.getId());
        return ResponseData.success(detail);
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(WarehouseMoveParam warehouseMoveParam) {
        return this.warehouseMoveService.findPageBySpec(warehouseMoveParam);
    }

    /**
     * 跳转到商品列表页面
     *
     * @author jinjing
     * @Date 2020-04-14
     */
    @RequestMapping("/initProductList")
    public String initProductList(Model model, HttpServletRequest request) {
        model.addAttribute("moveNum", StringUtil.getIDNumber(NumberUtilEnum.仓库移货.getName()));
        return PREFIX + "/warehouseMove_product_init.html";
    }

    /**
     * 仓库移货明细添加
     *
     * @author jinjing
     * @Date 2020-04-14
     */
    @RequestMapping("/addDealDetails")
    @ResponseBody
    public ResponseData addDealDetails(WarehouseMoveDetailVo detailVo) {
        return this.warehouseMoveService.addWarehouseMoveInfos(detailVo);
    }

    /**
     * 订单详情页面
     *
     * @author jinjing
     * @Date 2020-04-14
     */
    @RequestMapping("/showOrderDetailIndex")
    public String showOrderDetailIndex() {
        return PREFIX + "/warehouseMove_product_detail.html";
    }

    /**
     * 订单详情页面
     *
     * @author jinjing
     * @Date 2020-04-14
     */
    @ResponseBody
    @RequestMapping("/showOrderDetailInfos")
    public LayuiPageInfo showOrderDetailInfos(WarehouseMoveDetailParam warehouseMoveDetailParam) {
        return warehouseMoveDetailService.findPageBySpec(warehouseMoveDetailParam);
    }


    /**
     * 查询列表
     *
     * @author LuoYong
     * @Date 2020-04-20
     */
    /*@ResponseBody
    @RequestMapping("/listWarehouseMoveInfoDetail")
    public LayuiPageInfo listWarehouseMoveInfoDetail(WarehouseMoveProductParam productParam) {
        return this.warehouseMoveProductService.findPageBySpec(productParam);
    }*/

    /**
     * 查询当期用户所在门店的 商品库存信息
     *
     * @param productParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/listProductStockInfos")
    public LayuiPageInfo listProductStockInfos(WarehouseMoveParam productParam) {
        return this.warehouseMoveService.selectProductStockInfos(productParam);
    }
}
